﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BagPanel : BasePanel<BagPanel>
{
    public UIScrollView bag;
    public UIButton btnClose;
    public UIScrollView bagList;
    void Start()
    {
        Hide();        
        btnClose.onClick.Add(new EventDelegate(()=>
        {
            Hide();
        }));

        //动态创建30个图标
        for (int i=49; i>=0; i--)
        {
            GameObject obj = Instantiate(Resources.Load<GameObject>("Prefab/Item"));
            obj.transform.SetParent(bagList.transform, false);
            //通过代码来自己设置位置(将bagList节点的Grid脚本关闭)(注：坐标是由下至上，也就是添加的顺序是反的)
            float x = 160 * (i % 3);
            float y = 160 * (i / 3);
            Debug.LogFormat("i:{0} x:{1}-{2} y:{3}-{4}", i, x, i%3, y, i/3);
            obj.transform.localPosition = new Vector3(160 * (i % 3), 160 * (i/3), 0);
        }

        //通过代码，控制滚动条更新
        bagList.UpdateScrollbars();
    }
}
